package com.siecom.tool;

import android.view.View;


public abstract class MoreClickListener implements View.OnClickListener {

    public abstract void onMoreClick(View view);

    public long lastTime = System.currentTimeMillis();

    public int counts = 0;

    //可点解的次数
    public int times = 3;

    public int period = 1000;
    //设置点击多少次响应事件
    public void setTimes(int time){
        times = time;
    }

    /**
     * 设置点击时间间隔
     * @param timeOutMs  单位毫秒
     */
    public void setPeriod(int timeOutMs){
        this.period = timeOutMs;
    }

    @Override
    public void onClick(View view) {
        long thisTime = System.currentTimeMillis();
        long tmMs = thisTime - lastTime;
        lastTime = thisTime;
        if (tmMs < period){
            counts++;
        }else {
            counts = 0;
        }
        if (counts > times){
            onMoreClick(view);
            counts = 0;
        }

    }
}
